#coding:gbk

import os
import os.path
import smartcard as _sc

ROOT_DIR = "z:\\apps\\Tools\\PBOC3_TEST"

PRIVATE_CMD = "\t\tPRIVATE"

def process_select(cmd):

g_dict = {
    "A4" : "SELECT",
    "50" : "GP INIT UPDATE",
    "82" : "EXTERNAL AUTHENTICATE",

    "88" : "INTERNAL AUTHETICATE",
    "B2" : "READ RECORD",
    "A8" : "GPO",
    "20" : "PIN VERIFY",
    "AE" : "GAC",
    "CA" : "GET DATA",
    "1E" : "APP BLOCK",
    "16" : "CARD BLOCK",
    "18" : "APP UNBLOCK",
    "24" : "PIN CHANGE UNBLOCK",
    "DA" : "PUT DATA",
    "DC" : "UPDATE RECORD",

    "B4" : "READ CAPP DATA",
    "DE" : "UPDATE CAPP DATA",
    "E2" : "APPEND RECORD",
    "5A" : "GET TRANS PROVE",


    "42" : PRIVATE_CMD,
    "D0" : PRIVATE_CMD,
    "D1" : PRIVATE_CMD,
    "D2" : PRIVATE_CMD,
    "D4" : PRIVATE_CMD,
    "E0" : PRIVATE_CMD,
    "F2" : "GET STATUS",
}

def process_file_name(fileFullName):
    print fileFullName
    with open(fileFullName) as fObj:
        lines = fObj.readlines()
        for line in lines:
            line = line.strip()
            if line == "":
                continue
            elif line.startswith("//"):
                continue
            elif line.startswith("reset"):
                print "___________________reset"
            else:
                key = line[3:5]
                if key in g_dict:
                    print g_dict[key]
                else:
                    print "UNKOWN"
    print

def main():
    for root, dirs, files in os.walk(ROOT_DIR):
        for fileName in files:
            if fileName.endswith(".txt") or fileName.endswith(".scr") or fileName.endswith(".bat") or fileName.endswith(".py"):
                continue
            else:
                fileFullName = os.path.join(root, fileName)
                process_file_name(fileFullName)

main()

